package com.example.medicalequipment.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.example.medicalequipment.R;
import com.example.medicalequipment.entity.Device;

public class DeviceDetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_device_detail);

        ImageView ivDeviceImage = findViewById(R.id.ivDeviceImage);
        TextView tvTitle = findViewById(R.id.tvTitle);
        TextView tvCategory = findViewById(R.id.tvCategory);
        TextView tvCode = findViewById(R.id.tvCode);
        TextView tvFunction = findViewById(R.id.tvFunction);
        TextView tvIntroduction = findViewById(R.id.tvIntroduction);

        Intent intent = getIntent();
        if (intent != null && intent.hasExtra("device")) {
            Device device = (Device) intent.getSerializableExtra("device");
            if (device != null) {
                Glide.with(this)
                        .load(device.getImageResId())
                        .placeholder(R.drawable.devices_1)
                        .into(ivDeviceImage);

                tvTitle.setText(device.getName());
                tvCategory.setText("所属科室: " + device.getDepartment());
                tvCode.setText("设备编号: " + device.getCode());
                tvFunction.setText("设备功能: " + device.getFunction());
                tvIntroduction.setText("设备简介: " + device.getIntroduction());
            }
        }

        // 设置返回键逻辑
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onSupportNavigateUp() {
        onBackPressed();
        return true;
    }
}
